<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>个人中心</title>
		<meta name="viewport" content="initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="//cdn.bootcss.com/weui/0.4.3/style/weui.min.css">
		<link rel="stylesheet" href="//cdn.bootcss.com/jquery-weui/0.8.3/css/jquery-weui.min.css">
		<link rel="stylesheet" href="../css/index.css" />
	</head>
	<body id="wode">
		<section>
			<div>
				<input id="username" type="text" placeholder="请输入您的姓名" />
			</div>
			<div>
				<input id="phone" type="number" placeholder="请输入您的手机号" />
				<button type="button" id="sendCode" class="yzm">获取验证码</button>
			</div>
			<div>
				<input id="verifycode" type="number" placeholder="请输入验证码" />
			</div>
			<a href="javascript:;"  class="weui_btn weui_btn_primary login">下一步</a>
		</section>
		<script src="//cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
		<script src="//cdn.bootcss.com/jquery-weui/0.8.3/js/jquery-weui.min.js"></script>
		<script type="text/javascript" src="../js/basic.js" ></script>
		<script>
			var ip_addr = getUrl();	
			function checkPhone(phone) {
  				var reg = new RegExp("^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$", "g");
  				return reg.exec(phone);
			}
			$("#sendCode").click(function(){
				var phone = $("#phone").val();
				if(!checkPhone(phone)){
    				$.toptip('请输入正确的手机号！', 'warning');
    				return;
    			}
				var asd=60;
				/* 更改样式  */
				$("#sendCode").attr('disabled','disabled');
				$("#sendCode").text(asd+"s后再试");
				$("#sendCode").css({"color":"#333333","background":"#fff","border":"1px solid #04BE02"});
					
				//定时器和计时器
				timer=setInterval(function(){
					asd--;
					$("#sendCode").text(asd+"s后再试");
					
				},1000);
				setTimeout(function(){
					clearInterval(timer);
					/* 还原样式 */
					$("#sendCode").removeAttr('disabled');
					$("#sendCode").text("获取验证码");
					$("#sendCode").css({"color":"#FB4747","border":"1px solid #04BE02"});
				},60000);
				sendRegVerifyCode(phone)
			})
			function sendRegVerifyCode(phone) {
				//用户登录发送验证码	
				$.ajax({
					type: 'post',
					dataType: "json",
					url: ip_addr + 'user/sendRegVerifyCode',
					data: {
						phone: phone
					},
					success: function(data) {
						var result = data.rows;
						var innerHTML = '';
						if(data.code == 0) {
							$.toptip('发送验证码成功！', 'success');
						} else {
							$.toptip(data.msg, 'error');
						}
					}
				});
			}
			$(".login").click(function(){
				//注册下一步时验证验证码
				var username = $("#username").val();
				var phone = $("#phone").val();
				var verifyCode = $("#verifycode").val();
				
				//本地存储
				localStorage.setItem("username",username);
				localStorage.setItem("phone",phone);	
				
				if(username == '' || username == null){
					$.toptip('请输入姓名！', 'warning');
				}else if(phone == '' || phone == null){
					$.toptip('请输入手机号！', 'warning');
				}else if(verifyCode == '' || verifyCode == null){
					$.toptip('请输入验证码！', 'warning');
				}else{
					$.ajax({
						type: 'post',
						dataType: "json",
						url: ip_addr + 'user/addUserCheck',
						data: {
							phone: phone,
							verifyCode:verifyCode
						},
						success: function(data) {
							if(data.code == 0) {
								window.location.href = "register_b.html";
							} else {
								$.toast(data.msg, "cancel");
							}
						}
					});
				}
				
			})
		</script>
	</body>
</html>
 